﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KidsGest.Models;
using System.Web.Security;

namespace KidsGest.Controllers
{
    public class ResetPasswordController : Controller
    {
         //
        // GET: /ResetPassword/

        public ActionResult Index()
        {
            return View();
        }

        //Controllers for the reset page
        public ActionResult ResetPassword(string reset, string username)
        {
            if ((reset != null) && (username != null))
            {
                MembershipUser currentUser = Membership.GetUser(username);
                if (SendEmail.HashResetParams(currentUser.UserName, currentUser.ProviderUserKey.ToString()) == reset)
                {
                    ViewBag.newPass = currentUser.ResetPassword();
                    ViewBag.userName = username;
                    return View("ResetPasswordSuccess");
                }
            }

            return View();
        }

        [HttpPost]
        public ActionResult ResetPassword(ResetPasswordModel Model)
        {
            MembershipUser currentUser = Membership.GetUser(Model.Username);

            if (ModelState.IsValid)
            {
                SendEmail.SendResetEmail(currentUser);
                return Redirect("ResetPasswordSucess");
            }
            return View();
        }

        public ActionResult ResetPasswordSuccess(){

            return View();   
        }

    }

    }
